// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <random>
#include <pollux/type/type.h>
#include <pollux/vector/base_vector.h>

namespace kumo::pollux::test {

// sets child elements of null row/array/map to null. the result of
// 'a.b.c is null' can be determined just by looking at 'c' because
// a null parent 'b' is also null in 'c'. This makes generating
// testing filters simpler. Non-null content under a null container
// cannot be represented in file formats in any case.
void propagateNullsRecursive(BaseVector& vector);

struct BatchMaker {
  static VectorPtr createBatch(
      const TypePtr& type,
      uint64_t capacity,
      memory::MemoryPool& memoryPool,
      std::mt19937& gen,
      std::function<bool(vector_size_t /*index*/)> is_null_at = nullptr);

  static VectorPtr createBatch(
      const TypePtr& type,
      uint64_t capacity,
      memory::MemoryPool& memoryPool,
      std::function<bool(vector_size_t /*index*/)> is_null_at = nullptr,
      std::mt19937::result_type seed = std::mt19937::default_seed);

  template <TypeKind KIND>
  static VectorPtr createVector(
      const TypePtr& type,
      size_t size,
      memory::MemoryPool& pool,
      std::mt19937& gen,
      std::function<bool(vector_size_t /*index*/)> is_null_at = nullptr);

  template <TypeKind KIND>
  static VectorPtr createVector(
      const TypePtr& type,
      size_t size,
      memory::MemoryPool& pool,
      std::function<bool(vector_size_t /*index*/)> is_null_at = nullptr,
      std::mt19937::result_type seed = std::mt19937::default_seed) {
    std::mt19937 gen{seed};
    return createVector<KIND>(type, size, pool, gen, is_null_at);
  }
};

} // namespace kumo::pollux::test
